<template>
  <div>
    <el-table
      ref="singleTable"
      :data="tableData"
      highlight-current-row
      @current-change="handleCurrentChange"
      style="width: 100%"
    >
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column property="createTime" label="认证日期" width="120">
      </el-table-column>
      <el-table-column property="school" label="学校" width="120">
      </el-table-column>
      <el-table-column property="academy" label="学院" width="120">
      </el-table-column>
      <el-table-column property="certProfession" label="认证专业">
      </el-table-column>
      <el-table-column property="certProfessionType" label="认证专业类">
      </el-table-column>
      <el-table-column property="certCharge" label="专业认证人" width="120">
      </el-table-column>
      <el-table-column property="certLevel" label="认证级别">
      </el-table-column>
      <el-table-column property="certStage" label="认证阶段">
        <template slot-scope="scope">
          {{ getStage(scope.row.certStage) }}
        </template>
      </el-table-column>
      <el-table-column property="certStatus" label="认证结果">
        <template slot-scope="scope">
          {{ getStatus(scope.row.certStatus) }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="deal(scope.row.certStage, scope.row.id)"
            >处理</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      v-if="tableData.length > 0"
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="page.pageNum"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="page.pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          date: "2022-3-26",
          school: "阜阳师范大学",
          college: "物理与电子工程学院",
          major: "物理",
          type: "中学教育",
          name: "王五",
          level: "2",
          phase: "认证申请",
          result: "待审核",
          id: 1
        }
      ],
      currentRow: null,
      page: {
        pageNum: 1,
        pageSize: 10
      },
      totalPage: 0
    };
  },
  activated() {
    this.getCert();
  },
  methods: {
    // 每页数
      sizeChangeHandle (val) {
        this.page.pageSize = val
        this.page.pageNum = 1
        this.getCert()
      },
      // 当前页
      currentChangeHandle (val) {
        this.page.pageNum = val
        this.getCert()
      },
    setCurrent(row) {
      this.$refs.singleTable.setCurrentRow(row);
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    deal(certStage, id) {
      switch (certStage) {
        case 1:
          this.$router.push({
            path: "/manage-stepOne",
            query: {
              id: id
            }
          });
          break;
        case 2:
          this.$router.push({
            path: "/manage-stepTwo",
            query: {
              id: id
            }
          });
          break;
        case 3:
          this.$router.push({
            path: "/manage-stepThree",
            query: {
              id: id
            }
          });
          break;
        case 5:
          this.$router.push({
            path: "/manage-stepFive",
            query: {
              id: id
            }
          });
          break;
      }
    },
    // 查看认证列表
    getCert() {
      this.$http({
        url: this.$http.reviewed("/admin/certlist"),
        method: "get",
        params: this.$http.adornParams(
          {
            ...this.page
          },
          false
        )
      }).then(res => {
        this.tableData = res.data.data.records;
        this.totalPage = res.data.data.total
      });
    },
    getStatus(val) {
      let statusName = "";
      switch (val) {
        case 1:
          statusName = "认证中";
          break;
        case 2:
          statusName = "认证通过";
          break;
        case 3:
          statusName = "认证驳回";
          break;
      }
      return statusName;
    },
    getStage(val) {
      let statusName = "";
      switch (val) {
        case 1:
          statusName = "认证申请";
          break;
        case 2:
          statusName = "专业自评";
          break;
        case 3:
          statusName = "进校考察";
          break;
        case 4:
          statusName = "结论认定";
          break;
        case 5:
          statusName = "整改提高";
          break;
      }
      return statusName;
    }
  }
};
</script>
